/**
 * 产品修改js
 */
var comValidform=null;
var returnStatus=false;
var activityUpdate={
	activityUE:null,
	key:null,
	oldStatus:null,
		
	startEvent:function(){
		activityUpdate.showInfo();
		
		comValidform=$(".com-addForm").Validform({
			datatype:{
				"m0-2" : /^[0-9]+(.[0-9]{1,2})?$/
			},
			tiptype:2,
			tipSweep:true,
			beforeSubmit:function(curform){
				if(activityUpdate.oldStatus != 0){
					alert("活动已发布不允许修改");
					return false;
				}

				var url = 'mgr/activityCtrl/update';
				var params = jsUtils.serializeJson($('.com-addForm'));
				if(params.channel == undefined || params.channel == null){
					alert("请至少选择一个发布渠道！");
					return false
				}else{
					params.channel = params.channel.toString();
				}
				var cb = function(data){
					alert(data.msg);
					//成功返回
					if(data.resultCode==200){
						localStorage.removeItem(activityUpdate.key);
						//关闭窗口并刷新数据

						returnStatus=true;
					}
				};
				sendApiNoLoadSync(url, params, cb, 'POST');
				return false;
			}
		});
	},
	
	showInfo:function(){
		
		var id = art.dialog.data('updId');
		activityUpdate.key = id + "_activity_Key";
		activityInfo = eval('(' + localStorage.getItem(activityUpdate.key) + ')');
		$("input[name='id']").val(activityInfo.id);
		$("input[name='name']").val(activityInfo.name);
		$("input[name='url']").val(activityInfo.url);
		$("input[name='picAddress']").val(activityInfo.picAddress);
		$("textarea[name='actDesc']").val(activityInfo.actDesc);

		var startTime = '';
		if(activityInfo.startTime != null){
			startTime = (new Date(activityInfo.startTime)).format('yyyy-MM-dd');
		}

		var endTime = '';
		if(activityInfo.endTime != null){
			endTime = (new Date(activityInfo.endTime)).format('yyyy-MM-dd');
		}


		$("input[name='startTime']").val(startTime);

		$("input[name='endTime']").val(endTime);

		$("select[name='startStatus']").val(activityInfo.startStatus);

		$("select[name='isShare']").val(activityInfo.isShare);

		activityUpdate.oldStatus = activityInfo.status;

		if(activityInfo.channel != null){
			if(activityInfo.channel.indexOf("1") >= 0){
				$("input:checkbox[value='1']").attr('checked','true');
			}

			if(activityInfo.channel.indexOf("2") >= 0){
				$("input:checkbox[value='2']").attr('checked','true');
			}

			if(activityInfo.channel.indexOf("3") >= 0){
				$("input:checkbox[value='3']").attr('checked','true');
			}
		}

		if(activityInfo.status != 0){
			$("input[name='id']").attr("disabled", "disabled");
			$("input[name='id']").attr("disabled", "disabled");
			$("input[name='name']").attr("disabled", "disabled");
			$("input[name='url']").attr("disabled", "disabled");
			$("input[name='picAddress']").attr("disabled", "disabled");
			$("textarea[name='actDesc']").attr("disabled", "disabled");
			$("input[name='startTime']").attr("disabled", "disabled");

			$("input[name='endTime']").attr("disabled", "disabled");

			$("select[name='startStatus']").attr("disabled", "disabled");

			$("select[name='isShare']").attr("disabled", "disabled");


			$("input:checkbox[value='1']").attr("disabled", "disabled");
			$("input:checkbox[value='2']").attr("disabled", "disabled");
			$("input:checkbox[value='3']").attr("disabled", "disabled");
		}
	 
	},
	
	init:function(){
		activityUpdate.startEvent();
	}
}
$(document).ready(function() {
	activityUpdate.init();
});
function submitForm(){
	comValidform.submitForm();
	return returnStatus;
}